// managers/pages/copy_me/copy_me.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    listData: [],
  },

  getData() {
    wx.showLoading({
      title: '',
      icon: ''
    })
    var url = app.globalData.url + 'exam/getCopyExamMain',
      that = this,
      listData = [];

    app.wxRequest(url, {
      memberId: app.globalData.memberId
    }, res => {
      if (res.flag) {
        listData = res.data.examMainList;
        for (var i in listData) {
          var date = new Date(listData[i].submit_time.replace(/-/g, "/"));
          var time = "";
          if (date.getHours() > 12) {
            time = "下午";
          } else {
            time = "上午"
          }
          var afterTime = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() +
            ' ' + time + date.getHours() + ':' + date.getMinutes();
          listData[i].submit_time = afterTime;
          listData[i].submit_time = listData[i].submit_time;
        }
        wx.hideLoading()
        wx.stopPullDownRefresh()
        that.setData({
          listData
        })
        console.log(listData);
      }
    })
  },


  // 跳转到相应审批
  itemOpen(e) {
    console.log(e);
    var item = e.currentTarget.dataset.obj;
    if (item.exam_type == 0) {
      wx.navigateTo({
        url: '/approval/pages/leave_approval/leave_approval',
      })
    } else if (item.exam_type == 1) {
      wx.navigateTo({
        url: '/approval/pages/items_approval/items_approval',
      })
    } else if (item.exam_type == 2) {
      wx.navigateTo({
        url: '/approval/pages/depart_approval/depart_approval',
      })
    } else if (item.exam_type == 3) {
      item.noBtn = false;
      wx.navigateTo({
        url: '/approval/pages/leave_approval/leave_approval',
      })
    } else if (item.exam_type == 4) {
      wx.navigateTo({
        url: '/approval/pages/positive_apply/positive_apply',
      })
    } else if (item.exam_type == 5) {
      wx.navigateTo({
        url: '/approval/pages/return_approval/return_approval',
      })
    } else if (item.exam_type == 6) {
      wx.navigateTo({
        url: '/approval/pages/person_apply/person_apply',
      })
    }

    item.showBtn = true;
    item.detial = true;
    item.stautsApproval = false;
    wx.setStorageSync('readDataOa', true)
    wx.setStorageSync('examInfo', JSON.stringify(item))


  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getData()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.getData()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})